<?php
namespace Home\Controller\User;
use Think\Controller;
/*
 * 自制管理 2016.6.6
 * author:candy
 * 每个用户限制 20 个地址，可以设置默认地址
 * 
 */
class AddressController extends Controller {

    public function _empty($name){
        $this->display("Event:404");      
    }

    public function index(){
        $list = $this->listAddress(20);
        $this->assign('list',$list);
        $this->display("User:address");
    }
    /**
     * 6.6
     * 后期在添加地址前要判断用户有没有登入
     */
    public function addAddress(){
        $Address = M('Address');
        $sessionUser = session('user');
        $Address->create();
        $Address->user_id = $sessionUser['user_id'];
        return $Address->add();
    }

    public function listAddress($id){
        $Address = M('Address');
        $list = $Address->where(array('user_id'=>$id))->select();
        return $list;
    }
}